using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace LWRSSReader
{

	public class RssFeedWrapCollectionPropertyDescriptor : PropertyDescriptor
	{
		private RssFeedWrapCollection collection = null;
		private int index = -1;

		public RssFeedWrapCollectionPropertyDescriptor(RssFeedWrapCollection coll, int idx)
			: base("#" + idx.ToString(), null)
		{
			this.collection = coll;
			this.index = idx;
		}

		public override AttributeCollection Attributes
		{
			get
			{
				return new AttributeCollection(null);
			}
		}

		public override bool CanResetValue(object component)
		{
			return true;
		}

		public override Type ComponentType
		{
			get
			{
				return this.collection.GetType();
			}
		}

		public override string DisplayName
		{
			get
			{
				RssFeedWrap rssFeedWrap = this.collection[index];

				if (rssFeedWrap == null || rssFeedWrap.Url == String.Empty)
					return global::LWRSSReader.Properties.Resources.STR_FILL_IN_THE_FEEDS_URL;
				return rssFeedWrap.Url;
			}
		}

		public override string Description
		{
			get
			{

				RssFeedWrap rssFeedWrap = this.collection[index];
				StringBuilder sb = new StringBuilder();

				if (rssFeedWrap == null || rssFeedWrap.Url == String.Empty)
					return global::LWRSSReader.Properties.Resources.STR_FILL_IN_THE_FEEDS_URL;

				sb.Append(rssFeedWrap.Url);
				/*sb.Append(",");
				sb.Append(rssFeedWrap.Channels.Count);*/

				return sb.ToString();
			}
		}

		public override object GetValue(object component)
		{
			return this.collection[index];
		}

		public override bool IsReadOnly
		{
			get { return true; }
		}

		public override string Name
		{
			get { return "#" + index.ToString(); }
		}

		public override Type PropertyType
		{
			get
			{

				if (index < this.collection.Count)
					return this.collection[index].GetType();
				return null;

			}
		}

		public override void ResetValue(object component) { }

		public override bool ShouldSerializeValue(object component)
		{
			return true;
		}

		public override void SetValue(object component, object value)
		{
			// this.collection[index] = value;
		}

	}
}
